function UrlEncode(str) {
  return transform(str);
}

function transform(s) {
  var hex = ''
  var i, j, t

  j = 0
  for (i = 0; i < s.length; i++) {
    t = hexfromdec(s.charCodeAt(i));
    if (t == '25') {
      t = '';
    }
    hex += '%' + t;
  }
  return hex;
}

function hexfromdec(num) {
  if (num > 65535) { return ("err!") }
  var first = Math.round(num / 4096 - .5);
  var temp1 = num - first * 4096;
  var second = Math.round(temp1 / 256 - .5);
  var temp2 = temp1 - second * 256;
  var third = Math.round(temp2 / 16 - .5);
  var fourth = temp2 - third * 16;
  return ("" + getletter(third) + getletter(fourth));
}

function getletter(num) {
  if (num < 10) {
    return num;
  }
  else {
    if (num == 10) { return "A" }
    if (num == 11) { return "B" }
    if (num == 12) { return "C" }
    if (num == 13) { return "D" }
    if (num == 14) { return "E" }
    if (num == 15) { return "F" }
  }
}
Page({
  data:{
    url:''
  },
  onLoad:function(){
    //说明 i 代表公众号的unionid 没这个无法使用公众号的页面
    //appUnionid 算是项目的unionid 新加字段 区分不同的项目
    //问题？后台如何把appUnionid参数带过去呢
    var avatar = "https://wkcy2.sjwke.com/addons/tjtjtj_luntan/icon.jpg?v=1530263535";
    var url = "https://wkcy2.sjwke.com/app/index.php?i=34&c=entry&do=index&m=tjtjtj_luntan&uid=114&nickName=李宇翔&sex=1&avatar=" + UrlEncode(avatar);
    // var url = "https://www.sjwke.com/app/index.php?i=36&c=entry&do=index&m=tjtjtj_luntan&uid=114&nickName=李宇翔&sex=1&avatar=" + UrlEncode(avatar);
    console.log(url)
    wx.getUserInfo({
      success:function(e){
        console.log(e)
      },fail(e){
        console.log("fail")
        console.log(e)
      }
    })
    //&wxref=mp.weixin.qq.com#wechat_redirect
    // var userInfo = getApp().getCache("userinfo");
    // var openid = userInfo.openid;
    // if(!openid){
    //   wx.showToast({
    //     title: '请获取用户信息',
    //   })
    //   return false
    // }
    // url = url+"&openid="+openid.replace(/sns_wa_/img,'')+"&nickName="+userInfo.nickname;
    this.setData({url:url})
  }
})